home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1995 May / cd Ware (Juegos) Epimundo.iso / DOS / C / ASCFIL.ZIP / TEST2.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-01  |  2.0 KB  |  74 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4. #include <iostream.h>
  5. #include <stdlib.h>
  6. #include <fstream.h>
  7. #include <iomanip.h>
  8. #include <conio.h>
  9. #include "table.h"
  10. #include "record.h"
  11.  
  12.  
  13. struct AFILE
  14. {                            // Structure...
  15.    char name[21];
  16.    double amount;
  17.    int items;
  18. };
  19.  
  20.  
  21. AFILE afile;
  22.  
  23.  
  24. main()
  25. {
  26.     int total_items = 0;
  27.     double total_amount = 0;
  28.  
  29.     int stat;
  30.     Record record("ascii2.fld");       // Record Object passing .fld file
  31.  
  32.  
  33.     Table  table("ascii2.txt", &record);   // Table Object passing ascii file
  34.                                            // name, and pointer to record
  35.                                            // object...
  36.  
  37.  
  38.     int index = record.getFieldNum("AMOUNT");  // Init. Index passing field
  39.                                                // name to index on...
  40.  
  41.     int si = table.openIndex(&index,1);        // openIndex passing pointer
  42.                                                // to index, and number of
  43.                                                // fields indexing on...
  44.  
  45.  
  46.    clrscr();
  47.  
  48.    //** For Loop to read through the records...
  49.    //** Pass 'si' handle for sorted ordering, nothing for non sorted...
  50.    for (stat = table.gotoFirst(si); stat==TBL_OK; stat = table.gotoNext(si))
  51.    {
  52.        table.Get();                             // Get record into buffer.
  53.  
  54.        record.getField("NAME", afile.name);      // Read fields
  55.        record.getField("AMOUNT", afile.amount);
  56.        record.getField("ITEMS", afile.items);
  57.  
  58.        total_items  += afile.items;
  59.        total_amount += afile.amount;
  60.  
  61.        printf("Name   : %s\n", afile.name);           //  Display
  62.        printf("Amount : %8.2lf\n", afile.amount);
  63.        printf("Items  : %d\n", afile.items);
  64.        printf("______________________________\n\n");
  65.    }
  66.  
  67.    printf("Grand Total Amount = %11.2lf\n", total_amount);
  68.    printf("Grand Total Items  = %d\n\n", total_items);
  69.  
  70.  table.gotoFirst(si);
  71. return 0;
  72. }
  73.  
  74.